﻿using System;
using System.Linq;
using System.Threading;
using System.Windows.Media;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Inventory;
using Styx.Helpers;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;

namespace MIBWarlock
{
    public partial class Classname
    {

        #region DampenHarm

        public DateTime DampenHamLastCast;

        private Composite DampenHarm()
        {
            return new Decorator(
/*
                ret =>
                MIBSettings.Instance.DampenHam &&
                SpellManager.HasSpell("Dampen Harm") &&
                DampenHamLastCast + TimeSpan.FromMilliseconds(5000) < DateTime.Now &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                Me.HealthPercent <= MIBSettings.Instance.DampenHamHP &&
                GetSpellCooldown("Dampen Harm").TotalMilliseconds <= MyLatency,
                new Action(delegate
                {
                    //SafelyFacingTarget(Me.CurrentTarget);
                    CastSpell("Dampen Harm", Me, "DampenHarm");
                    DampenHamLastCast = DateTime.Now;
                    return RunStatus.Failure;
                })
 */
                );
        }

        #endregion

        #region DiffuseMagic

        private Composite DiffuseMagic()
        {
            return new Decorator(
 /*
                ret =>
                MIBSettings.Instance.DiffuseMagic &&
                SpellManager.HasSpell("Diffuse Magic") &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                Me.HealthPercent <= MIBSettings.Instance.DiffuseMagicHP &&
                CountDebuffMagic(Me) >= MIBSettings.Instance.DiffuseMagicDebuff &&
                GetSpellCooldown("Diffuse Magic").TotalMilliseconds <= MyLatency,
                new Action(delegate
                {
                    //SafelyFacingTarget(Me.CurrentTarget);
                    CastSpell("Diffuse Magic", Me, "DiffuseMagic");
                })
*/
                );
        }

        #endregion

        #region Interrupt

        private static DateTime _lastInterrupt;

        #endregion

        #region PendingSpellRemove

        public void PendingSpellRemove()
        {
            if (Me.CurrentPendingCursorSpell != null &&
                !PendingSpellStopWatch.IsRunning)
            {
                PendingSpellStopWatch.Reset();
                PendingSpellStopWatch.Start();
            }

            if (Me.CurrentPendingCursorSpell != null &&
                PendingSpellStopWatch.IsRunning &&
                PendingSpellStopWatch.Elapsed.TotalMilliseconds > MIBSettings.Instance.PendingSpellStopWatchDuration)
            {
                Lua.DoString("RunMacroText(\"/cast Jab\")");
                PendingSpellStopWatch.Stop();
            }
        }

        #endregion

        #region RestRotation

        public Composite RestRotation()
        {
            return new Decorator(
                ret =>
                MIBSettings.Instance.UseFoodDrink &&
                !Me.IsDead &&
                !Me.IsGhost &&
                !Me.Mounted &&
                !Me.IsCasting &&
                !IsOverrideModeOn &&
                !Me.IsMoving,
                new PrioritySelector(
                    new Decorator(
                        ret =>
                        Me.ManaPercent < MIBSettings.Instance.StartEating &&
                        !Me.IsSwimming &&
                        !Me.HasAura("Drink") &&
                        Consumable.GetBestDrink(false) != null,
                        new Action(delegate
                        {
                            Thread.Sleep(TimeSpan.FromMilliseconds(300));

                            if (!Me.HasAura("Drink"))
                            {
                                Styx.CommonBot.Rest.DrinkImmediate();
                                StyxWoW.SleepForLagDuration();
                            }

                            if (Me.HasAura("Drink") &&
                                (Me.ManaPercent <
                                 MIBSettings.Instance.DoNotHealAbove ||
                                !Me.Combat))
                            {
                                return RunStatus.Running;
                            }
                            return RunStatus.Success;
                        }
                            ))
                    ));
        }

        #endregion

        #region UseRacial

        private Composite UseRacial()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && DebuffCCDuration(Me, 3000) &&
                    SpellManager.HasSpell("Every Man for Himself") &&
                    !Me.HasAura("Sap") &&
                    SpellManager.Spells["Every Man for Himself"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        if (MIBSettings.Instance.AutoTarget && Me.CurrentTarget == null &&
                            ValidUnit(MyLastTarget))
                        {
                            MyLastTarget.Target();
                        }

                        if (DebuffCCBreakonDamage(Me) &&
                            DebuffDot(Me))
                        {
                            Logging.Write(" - Warte auf Dot / Hand der Aufopferung unterbricht es!");
                        }
                        else
                        {
                            Logging.Write(" - Benutze: Jeder für sich");
                            CastSpell("Every Man for Himself", Me);
                        }
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && Me.HealthPercent < MIBSettings.Instance.DoNotHealAbove &&
                    SpellManager.HasSpell("Stoneform") &&
                    SpellManager.Spells["Stoneform"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        {
                            Logging.Write("Steingestalt");
                            CastSpell("Stoneform", Me);
                        }
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    Me.Combat &&
                    MIBSettings.Instance.AutoRacial && Me.HealthPercent < MIBSettings.Instance.DoNotHealAbove &&
                    SpellManager.HasSpell("Gift of the Naaru") &&
                    SpellManager.Spells["Gift of the Naaru"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        {
                            Logging.Write("Gabe der Naaru");
                            CastSpell("Gift of the Naaru", Me);
                        }
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    Me.Combat &&
                    SpellManager.HasSpell("Arcane Torrent") && SpellManager.HasSpell("Holy Insight") &&
                    (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) &&
                    SpellManager.Spells["Arcane Torrent"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        {
                            Logging.Write("Arkaner Strom");
                            CastSpell("Arcane Torrent", Me);
                        }
                        return RunStatus.Failure;
                    }))
                );
        }

        #endregion

        #region UseTrinket

        private Composite UseTrinket()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 1 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " auf Cooldown");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 2 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " auf Cooldown (Bosskampf)");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 3 &&
                    MIBSettings.Instance.Burst &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " auf Burst Modus");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 4 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    DebuffCCDuration(Me, 3000) && !Me.HasAura("Sap"),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " wegen CC");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 5 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.HealthPercent < MIBSettings.Instance.Trinket1HP &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " wegen Low HP");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 7 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.Trinket1HP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " wegen Gegner HP ist Low");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket1 == 8 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.ManaPercent < MIBSettings.Instance.Trinket1HP &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                      " wegen Low Mana");
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                        return RunStatus.Failure;
                    })),
                //Trinket 2
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 1 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " auf Cooldown");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 2 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " auf Cooldown (Bosskampf)");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 3 &&
                    MIBSettings.Instance.Burst &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " wegen Burst Modus");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 4 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    DebuffCCDuration(Me, 3000) && !Me.HasAura("Sap"),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " wegen CC");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 5 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.HealthPercent < MIBSettings.Instance.Trinket2HP &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " wegen Low HP");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 7 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.Trinket2HP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " wegen Gegner Low HP");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.Trinket2 == 8 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.ManaPercent < MIBSettings.Instance.Trinket2HP &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                      " wegen Low Mana");
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                        return RunStatus.Failure;
                    }))
                );
        }

        #endregion

        #region UseProfession

        private Composite UseProfession()
        {
            return new PrioritySelector(
                //Ingenieur
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 1 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Attackable(Me.CurrentTarget, 30) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Handschuhe Buff Aktiviert auf Cooldown");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 2 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 30) &&
                    Me.CurrentTarget.IsBoss &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Handschuhe Buff Aktiviert auf Cooldown (Bosskampf)");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 3 &&
                    MIBSettings.Instance.Burst &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Attackable(Me.CurrentTarget, 30) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                    {
                        Logging.Write("Aktiviere: Handschuhe Buff Aktiviert wegen Burst Modus");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 4 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands) &&
                    DebuffCCDuration(Me, 3000),
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Handschuhe Buff Aktiviert wegen CC");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 5 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Me.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Handschuhe Buff Aktiviert wegen Low HP");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 7 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Handschuhe Buff Aktiviert wegen Gegner Low HP");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 8 &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.Inventory.Equipped.Hands != null &&
                    Me.ManaPercent < MIBSettings.Instance.ProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Handschuhe Buff Aktiviert wegen Low Mana");
                        StyxWoW.Me.Inventory.Equipped.Hands.Use();

                        return RunStatus.Failure;
                    })),
                //Kräuterkunde
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 1 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 5) &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut Aktiviert auf Cooldown");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 2 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 50) &&
                    Me.CurrentTarget.IsBoss &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut Aktiviert auf Cooldown");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 3 &&
                    MIBSettings.Instance.Burst &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut Aktiviert wegen Burst Modus");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 4 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    DebuffCCDuration(Me, 3000) &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut wegen CC");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 5 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut wegen Low HP");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 7 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Attackable(Me.CurrentTarget, 5) &&
                    !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.HealthPercent < MIBSettings.Instance.ProfBuffHP &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut Aktiviert wegen Gegner Low HP");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    })),
                new Decorator(
                    ret =>
                    MIBSettings.Instance.ProfBuff == 8 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    Me.Combat &&
                    !Me.IsChanneling &&
                    Me.ManaPercent < MIBSettings.Instance.ProfBuffHP &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= MyLatency,
                    new Action(delegate
                    {
                        Logging.Write("Benutze: Lebensblut Aktiviert wegen Low Mana");
                        CastSpell("Lifeblood", Me);
                        return RunStatus.Failure;
                    }))
                );
        }

        #endregion
    }
}